﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rel.Expressions
{
    public abstract partial class RegBase
    {

        internal QuantifierType quantifier = QuantifierType.None;
        protected int quantifierMin=0;
        protected int quantifierMax=0;

		/// <summary>
		/// Indicates the regbase decorator should repeat zero or more times.
		/// </summary>
		/// <returns>The or more.</returns>
        public RegBase ZeroOrMore()
        {
            quantifier = QuantifierType.ZeroOrMore;
            return this;
        }

		/// <summary>
		/// Indicates the regbase decorator should repeat Zero or One times.
		/// </summary>
		/// <returns>The or one.</returns>
        public RegBase ZeroOrOne()
        {
            quantifier = QuantifierType.ZeroOrOne;
            return this;
        }

		/// <summary>
		/// Indicates the regbase decorator should repeat One or More times.
		/// </summary>
        public RegBase  OneOrMore()
        {
            quantifier = QuantifierType.OneOrMore;
            return this;
        }

		/// <summary>
		/// Indicates the regbase decorator should repeat at least One time.
		/// </summary>
        public RegBase One()
        {
            quantifier = QuantifierType.One;
            return this;
        }

		/// <summary>
		/// Indicates the regbase decorator should repeats an exact number of times.
		/// </summary>
		/// <param name="exactlyqty">Exactlyqty.</param>
        public RegBase Exactly(int exactlyqty)
        {
            quantifier = QuantifierType.Exactly;
            quantifierMin = exactlyqty;
            
            if (exactlyqty < 1) throw new ArgumentOutOfRangeException("Character count must be exactly one.");
            
            return this;
        }

		/// <summary>
		/// Indicates the regbase decorator should repeats between min and max.
		/// </summary>
		/// <param name="min">Minimum.</param>
		/// <param name="max">Max.</param>
        public RegBase Between(int min, int max)
        {
            quantifierMin = min;
            quantifierMax = max;

            if (min < max) throw new Exception("Minimum character count must be less than maximum");

            if (min < 0 || max < 0) throw new ArgumentOutOfRangeException("Character count(s) must be greater than 0");

            quantifier = QuantifierType.Between;
            
            return this;
        }

		/// <summary>
		/// Indicates the regbase decorator should repeats at least x times.
		/// </summary>
		/// <returns>The least.</returns>
		/// <param name="atleastqty">Atleastqty.</param>
        public RegBase AtLeast(int atleastqty)
        {
            if (atleastqty < 0) throw new ArgumentOutOfRangeException("Character count must be greater than 0");

            quantifierMin = atleastqty;
            quantifier = QuantifierType.AtLeast;
            
            return this;
        }



    }
}
